package com.yksj.healthtalk.ui.friend;

import org.handmark.pulltorefresh.library.PullToRefreshBase;
import org.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;
import org.handmark.pulltorefresh.library.PullToRefreshScrollView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.universalimageloader.core.ImageLoader;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.graphics.drawable.LevelListDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.util.TypedValue;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.yksj.healthtalk.comm.BaseFragmentActivity;
import com.yksj.healthtalk.comm.LodingFragmentDialog;
import com.yksj.healthtalk.comm.SingleBtnFragmentDialog;
import com.yksj.healthtalk.comm.ZoomImgeDialogFragment;
import com.yksj.healthtalk.entity.CustomerInfoEntity;
import com.yksj.healthtalk.net.http.HttpRestClient;
import com.yksj.healthtalk.net.http.JsonsfHttpResponseHandler;
import com.yksj.healthtalk.net.http.ObjectHttpResponseHandler;
import com.yksj.healthtalk.net.socket.SmartFoxClient;
import com.yksj.healthtalk.services.CoreService;
import com.yksj.healthtalk.services.MessagePushService;
import com.yksj.healthtalk.ui.R;
import com.yksj.healthtalk.ui.app.AppData;
import com.yksj.healthtalk.ui.app.HTalkApplication;
import com.yksj.healthtalk.ui.doctor.DoctorCommonServiceActivity;
import com.yksj.healthtalk.ui.doctor.DoctorInterviewServiceActivity;
import com.yksj.healthtalk.ui.doctor.DoctorServiceActivity;
import com.yksj.healthtalk.ui.doctor.DoctorTimeServiceActivity;
import com.yksj.healthtalk.ui.doctorstation.DocotrStationHelperActivity;
import com.yksj.healthtalk.ui.messageleave.DoctorMessageBoardClient;
import com.yksj.healthtalk.ui.salon.SalonAboutOthersActivity;
import com.yksj.healthtalk.ui.setting.PersonalInformationActivity;
import com.yksj.healthtalk.ui.views.DoctorInfoBtnView;
import com.yksj.healthtalk.ui.views.DoctorInfoBtnView.OnClickDoctorServiceButtonListener;
import com.yksj.healthtalk.utils.CollectUtils;
import com.yksj.healthtalk.utils.DataParseUtil;
import com.yksj.healthtalk.utils.FriendHttpUtil;
import com.yksj.healthtalk.utils.JsonParseUtils;
import com.yksj.healthtalk.utils.PersonInfoUtil;
import com.yksj.healthtalk.utils.ToastUtil;
import com.yksj.healthtalk.utils.ViewUtils;

/**
 * @author root
 * 医生资料
 */
public class DoctorMainActivity extends BaseFragmentActivity implements OnClickListener, OnRefreshListener<ScrollView>,OnClickDoctorServiceButtonListener{
	private ImageView head;
	private TextView special;
	private TextView name_num;
	private ImageView sex_icon;
	private TextView hospital;
	private TextView title_departments;
	private TextView address;
	private LinearLayout collectLin;
	private LinearLayout collectLin_40;
	private LinearLayout noCollectLin;
	private LinearLayout noCollectLin_40;
	// private String type;// 0-从医生馆中 1-从社交场中
	private ImageLoader mImageLoader;
	private AppData mAppData;
	private CustomerInfoEntity mCustomerInfoEntity;
	private CustomerInfoEntity cacheCustomerInfoEntity;
	private PullToRefreshScrollView mPullRefreshScrollView;
	private Intent intent;
	private LodingFragmentDialog dialog;
	private LinearLayout mBtnLin;// 下面的按钮布局
	private DoctorInfoBtnView btnView;// 按钮
	BroadcastReceiver receiver = new BroadcastReceiver() {

		@Override
		public void onReceive(Context context, Intent intent) {
			LodingFragmentDialog.dismiss(getSupportFragmentManager());
			if(intent.getAction().equals(MessagePushService.ACTION_MESSAGE)){
				if (mCustomerInfoEntity != null && mMessageTv != null) {
					int size = HTalkApplication.getAppData().getNoReadMesgSize(mCustomerInfoEntity.getId());
					if (HTalkApplication.getAppData().getNoReadMesgSize(mCustomerInfoEntity.getId()) != 0) {
						mMessageTv.setText(size + "");
						mMessageTv.setVisibility(View.VISIBLE);
					} else {
						mMessageTv.setVisibility(View.GONE);
					}
				}
				
			}else {
				String result = intent.getStringExtra("result");
				if (result.equals("-1")) {
					ToastUtil.showShort(DoctorMainActivity.this,R.string.against__blacklist_operations);
				} else if (result.equals("0")) {
					ToastUtil.showShort(DoctorMainActivity.this,R.string.groupNewFail);
					return;
				} else {
					FriendHttpUtil.requestAttentionTofriendsResult(DoctorMainActivity.this, cacheCustomerInfoEntity,
							mAppData);
					switch (cacheCustomerInfoEntity.getAttentionFriendFlag()) {
					case 7:
					case 5:// 取消客户收藏成功
					case 0:// 取消关注成功
					case 9:// 取消关注合作者
						collectLin.setVisibility(View.VISIBLE);
						collectLin_40.setVisibility(View.VISIBLE);
						noCollectLin.setVisibility(View.GONE);
						noCollectLin_40.setVisibility(View.GONE);
						break;
					case 6:
					case 4:// 客户收藏成功
					case 1:// 关注成功
					case 8:// 合作者
						collectLin.setVisibility(View.GONE);
						collectLin_40.setVisibility(View.GONE);
						noCollectLin.setVisibility(View.VISIBLE);
						noCollectLin_40.setVisibility(View.VISIBLE);
						break;
					case 2:// 加入黑名单成功
						changeBlank(true);
						collectLin.setVisibility(View.VISIBLE);
						collectLin_40.setVisibility(View.VISIBLE);
						noCollectLin.setVisibility(View.GONE);
						noCollectLin_40.setVisibility(View.GONE);
						break;
					case 3:// 取消黑名单成功
						changeBlank(false);
						break;
					}
					// 对话按钮的文字
					// chatBtn.setText(FriendUtil.getChattingBtnText(
					// SmartFoxClient.getLoginUserInfo(), mCustomerInfoEntity));
				}
			}
			}
	};
	private ImageView level;//医生等级
	private TextView mMessageTv;
	private TextView mDoctorMessage;//医生公告
	private TextView blankText;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.doctor_infomation);
		initView();
		intent = getIntent();
		if (intent.hasExtra("id")) {
			initData(null, null, intent.getStringExtra("id"));
		} else if (intent.hasExtra("info")) {
			if (intent.getExtras().get("info") instanceof CustomerInfoEntity) {
				onBounData((CustomerInfoEntity) intent.getExtras().get("info"));
			}
		}
	}
	/**
	 * 绑定数据
	 * @param mInfoEntity
	 */
	private void onBounData(CustomerInfoEntity mInfoEntity) {
		findViewById(android.R.id.content).setVisibility(View.VISIBLE);
		if (dialog != null) {
			dialog.dismissAllowingStateLoss();
			dialog = null;
		}
		titleRightBtn2.setOnClickListener(this);
		titleRightBtn2.setBackgroundResource(R.drawable.icon_ziliao);
		mCustomerInfoEntity = mInfoEntity;
		mImageLoader = ImageLoader.getInstance();
		mAppData = HTalkApplication.getAppData();

		if(SmartFoxClient.getLoginUserInfo().isDoctor()){
			ViewUtils.setGone(findViewById(R.id.btn_lay), true);
		}else{
			ViewUtils.setGone(findViewById(R.id.btn_lay_40), true);
		}
		
		// 关注和取消关注按钮
		if (mInfoEntity.getIsAttentionFriend() == 0) {// 客户关系标记 0-无关系
			collectLin.setVisibility(View.VISIBLE);
			noCollectLin.setVisibility(View.GONE);
			collectLin_40.setVisibility(View.VISIBLE);
			noCollectLin_40.setVisibility(View.GONE);
		} else if (mInfoEntity.getIsAttentionFriend() == 1) {// 1-我关注
			collectLin.setVisibility(View.GONE);
			noCollectLin.setVisibility(View.VISIBLE);
			collectLin_40.setVisibility(View.GONE);
			noCollectLin_40.setVisibility(View.VISIBLE);
		} else if (2 == mInfoEntity.getIsAttentionFriend()) {// 2-黑名单
			changeBlank(true);
		} else if (3 == mInfoEntity.getIsAttentionFriend()|| mInfoEntity.getIsAttentionFriend() == 4) {// 客户
			collectLin.setVisibility(View.GONE);
			noCollectLin.setVisibility(View.VISIBLE);
			collectLin_40.setVisibility(View.GONE);
			noCollectLin_40.setVisibility(View.VISIBLE);
		}else if(5 == mInfoEntity.getIsAttentionFriend()){//我的合作者
			collectLin.setVisibility(View.GONE);
			noCollectLin.setVisibility(View.VISIBLE);
			collectLin_40.setVisibility(View.GONE);
			noCollectLin_40.setVisibility(View.VISIBLE);
		}
		level.setImageLevel(mCustomerInfoEntity.getDoctorLevel());
		titleTextV.setText(mInfoEntity.getDoctorName() + "医生诊所");
		// 头像
		mImageLoader.displayImage(mInfoEntity.getSex(),mInfoEntity.getNormalHeadIcon(), head);
		// 昵称和多美号
		String name = String.format(getString(R.string.name_num),mInfoEntity.getDoctorName(), mInfoEntity.getUsername());
		SpannableStringBuilder span = new SpannableStringBuilder(name.toString());
		int index1 = name.indexOf("(");
		int index2 = name.indexOf(")");
		span.setSpan(new AbsoluteSizeSpan((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 15, getResources().getDisplayMetrics()) + 1), 0, index1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		span.setSpan(new AbsoluteSizeSpan((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 13, getResources().getDisplayMetrics()) + 1), index1, index2,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		name_num.setText(span);
		// 年龄
		// if (!TextUtils.isEmpty(mInfoEntity.getAge())) {
		// }
		// 职称和科室
		String office2 = mInfoEntity.getOfficeName2();
		if (!TextUtils.isEmpty(office2)) {
			office2 = "," + office2;
		}
		if (!TextUtils.isEmpty(mInfoEntity.getOfficeName1())) {
			title_departments.setText(mInfoEntity.getDoctorTitle() + "/"+ mInfoEntity.getOfficeName1() + "");
		} else {
			title_departments.setText(mInfoEntity.getDoctorTitle());
		}
		// 医院
		hospital.setText(mInfoEntity.getHospital());
		// 地址
		if (!TextUtils.isEmpty(mInfoEntity.getDoctorWorkaddress())) {
			address.setText(mInfoEntity.getDoctorWorkaddress());
		}
		// 专长
		if (!TextUtils.isEmpty(mInfoEntity.getSpecial())) {
			StringBuilder b = new StringBuilder();
			b.append("医生专长").append("\n").append(mInfoEntity.getSpecial());
			SpannableStringBuilder builder = new SpannableStringBuilder(b.toString());
			builder.setSpan(new ForegroundColorSpan(Color.BLACK), 0, 4,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			builder.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.tag_note)), 4, b.toString().length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			builder.setSpan(new AbsoluteSizeSpan(14,true), 4, b.toString().length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			special.setText(builder);
		} else {
			special.setText("医生专长");
		}
		
		//医生公告
		if(!TextUtils.isEmpty(mInfoEntity.getDoctorMessage())){
			StringBuilder b=new StringBuilder();
			b.append("医生公告").append("\n").append(mInfoEntity.getDoctorMessage());
			SpannableStringBuilder builder=new SpannableStringBuilder(b.toString());
			builder.setSpan(new ForegroundColorSpan(Color.BLACK),0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			builder.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.tag_note)),4, b.toString().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			builder.setSpan(new AbsoluteSizeSpan(14,true),4, b.toString().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			mDoctorMessage.setText(builder);
		}else{
			StringBuilder b=new StringBuilder();
			b.append("医生公告").append("\n").append("欢迎您的光临，很高兴为您服务!");
			SpannableStringBuilder builder=new SpannableStringBuilder(b.toString());
			builder.setSpan(new ForegroundColorSpan(Color.BLACK),0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			builder.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.tag_note)),4, b.toString().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			builder.setSpan(new AbsoluteSizeSpan(14,true),4, b.toString().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			mDoctorMessage.setText(builder);
		}
		
		// 性别
		LevelListDrawable listDrawable = (LevelListDrawable) sex_icon.getDrawable();
		listDrawable.setLevel(Integer.valueOf(mInfoEntity.getSex()));
		//消息条数
		int size = HTalkApplication.getAppData().getNoReadMesgSize(mInfoEntity.getId());
		if (HTalkApplication.getAppData().getNoReadMesgSize(mInfoEntity.getId()) != 0) {
			mMessageTv.setText(size + "");
			mMessageTv.setVisibility(View.VISIBLE);
		} else {
			mMessageTv.setVisibility(View.GONE);
		}
		
		TextView textView= (TextView) findViewById(R.id.talk_text);
		textView.setText(PersonInfoUtil.getTalkName(true));
	}


	private void initView() {
		initTitle();
		titleLeftBtn.setOnClickListener(this);
		titleRightBtn2.setOnClickListener(this);
		titleRightBtn2.setVisibility(View.VISIBLE);
		findViewById(android.R.id.content).setVisibility(View.GONE);
		head = (ImageView) findViewById(R.id.info_head);// 头像
		name_num = (TextView) findViewById(R.id.info_name);// 昵称和多美号
		sex_icon = (ImageView) findViewById(R.id.sex);// 性别
		level = (ImageView)findViewById(R.id.level);
		title_departments = (TextView) findViewById(R.id.title_departments);// 职称和科室
		hospital = (TextView) findViewById(R.id.hospital);// 医院
		address = (TextView) findViewById(R.id.address);// 地址
		special = (TextView) findViewById(R.id.special);// 专长
		collectLin = (LinearLayout) findViewById(R.id.info_collect);// 关注按钮
		collectLin_40 = (LinearLayout) findViewById(R.id.info_collect_40);// 关注按钮
		noCollectLin = (LinearLayout) findViewById(R.id.delete);// 取消关注
		noCollectLin_40 = (LinearLayout) findViewById(R.id.delete_40);// 取消关注
		mMessageTv = (TextView) findViewById(R.id.item_dele);
		
		findViewById(R.id.talk_lin).setOnClickListener(this);
		findViewById(R.id.talk_lin_40).setOnClickListener(this);
		findViewById(R.id.info_recommend).setOnClickListener(this);
		findViewById(R.id.info_recommend_40).setOnClickListener(this);
		mPullRefreshScrollView = (PullToRefreshScrollView) findViewById(R.id.pull_refresh_scrollview);
		mBtnLin = (LinearLayout) findViewById(R.id.lin_btn);
		// 设置监听器
		mPullRefreshScrollView.setOnRefreshListener(this);
		collectLin.setOnClickListener(this);
		collectLin_40.setOnClickListener(this);
		blankText = (TextView)findViewById(R.id.blank_text);
		blankText.setOnClickListener(this);
		noCollectLin.setOnClickListener(this);
		noCollectLin_40.setOnClickListener(this);
		head.setOnClickListener(this);
		mDoctorMessage = (TextView) findViewById(R.id.doctor_message);
		mDoctorMessage.setOnClickListener(this);
	}

	/**
	 * 拉黑 控件操作
	 * 
	 * isBlank true 显示取消拉黑
	 * @param isBlank
	 */
	private void changeBlank(boolean isBlank){
		if(isBlank){
			blankText.setText("取消拉黑");
			blankText.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.person_quxiao_lahei),null, null);
		}else{
			blankText.setText("拉黑");
			blankText.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.person_lahei),null, null);
		}
		
	}
	
	private void initData(String type, String qrCode, String id) {
		btnView = new DoctorInfoBtnView(this);
		HttpRestClient.doHttpFindCustomerInfoByCustId(type, qrCode, id,
				SmartFoxClient.getLoginUserId(),
				new ObjectHttpResponseHandler(this) {
					private CustomerInfoEntity mInfoEntity;
					@Override
					public Object onParseResponse(String content) {
						try {
							Object object = JsonParseUtils.filterErrorMessage(content);
							//如果失败,就把失败信息返回
							if (object != null && object instanceof String) {
								return object.toString();
							} else {//否则 进行解析
								return DataParseUtil.jsonToCustmerInfo(new JSONObject(content));
							}
						} catch (JSONException e) {
							return null;
						}
						
					}

					@Override
					public void onSuccess(int statusCode, Object response) {
						super.onSuccess(statusCode, response);
						if (response != null&& response instanceof CustomerInfoEntity) {
							mInfoEntity = (CustomerInfoEntity) response;
							onBounData(mInfoEntity);
							//没有任何功能
							try {
								JSONArray array=new JSONArray(mInfoEntity.getServiceTypes());
								if(array==null|| 0==array.length()){
									findViewById(R.id.lin_btn).setVisibility(View.GONE);
									findViewById(R.id.my_view).setVisibility(View.VISIBLE);
								}else{
									btnView.setServiceType(mInfoEntity.getServiceTypes());
									if (mBtnLin.getChildCount() != 0) {
										mBtnLin.removeAllViews();
										
									}
									mBtnLin.addView(btnView);
								}
							} catch (Exception e) {
								
							}
						} else {
							ToastUtil.showShort(getApplicationContext(),response.toString());
							finish();
						}
					}
					@Override
					public void onFinish() {
						super.onFinish();
						if (mPullRefreshScrollView != null
								&& mPullRefreshScrollView.isRefreshing()) {
							mPullRefreshScrollView.onRefreshComplete();
						}
					}
					@Override
					public void onStart() {
						super.onStart();
						if (mPullRefreshScrollView != null
								&& !mPullRefreshScrollView.isRefreshing()) {
							mPullRefreshScrollView.setRefreshing();
						}
					}
				});
	}

	@Override
	protected void onStart() {
		//显示引导
		Intent intent =new Intent(this,CoreService.class);
		intent.setAction(CoreService.ACTION_FRAME_VIEW_VISIABLE);
		intent.putExtra("className",this.getClass().getName());
		startService(intent);
		//显示消息条数
		if (mCustomerInfoEntity != null) {
			int size = HTalkApplication.getAppData().getNoReadMesgSize(mCustomerInfoEntity.getId());
			if (HTalkApplication.getAppData().getNoReadMesgSize(mCustomerInfoEntity.getId()) != 0) {
				mMessageTv.setText(size + "");
				mMessageTv.setVisibility(View.VISIBLE);
			} else {
				mMessageTv.setVisibility(View.GONE);
			}
		}
		
		IntentFilter filter = new IntentFilter(MessagePushService.ACTION_COLLECT_FRIEND);
		filter.addAction(CollectUtils.ACTION_FRIEND_INFO);
		filter.addAction(MessagePushService.ACTION_MESSAGE);
		registerReceiver(receiver, filter);
		super.onStart();
	}

	@Override
	protected void onStop() {
		unregisterReceiver(receiver);
		super.onStop();
	}

	@Override
	public void onClick(View v) {
		Intent intent = null;
		switch (v.getId()) {
		case R.id.title_back:
			onBackPressed();
			break;
		case R.id.blank_text:
			if (!mCustomerInfoEntity.getId().equals(SmartFoxClient.getLoginUserId())) {
				cacheCustomerInfoEntity = FriendHttpUtil.requestAttentionTofriends(this, true,mCustomerInfoEntity);
			}
			break;
		case R.id.talk_lin:
		case R.id.talk_lin_40:
			FriendHttpUtil.onItemClick(this, mCustomerInfoEntity);
			break;
		case R.id.info_collect:
		case R.id.info_collect_40:
			if (!mCustomerInfoEntity.getId().equals(SmartFoxClient.getLoginUserId())) {
				cacheCustomerInfoEntity = FriendHttpUtil.requestAttentionTofriends(this, null,mCustomerInfoEntity);
			}
			break;
		case R.id.delete:
		case R.id.delete_40:
			if (!mCustomerInfoEntity.getId().equals(SmartFoxClient.getLoginUserId())) {
				cacheCustomerInfoEntity = FriendHttpUtil.requestAttentionTofriends(this, null,mCustomerInfoEntity);
			}
			break;
		case R.id.title_right2:
			if (mCustomerInfoEntity.getId().equals(SmartFoxClient.getLoginUserId())) {
				intent = new Intent(DoctorMainActivity.this,PersonalInformationActivity.class);
			} else {
				intent = new Intent(DoctorMainActivity.this,FriendInformUI.class);
				intent.putExtra("id", mCustomerInfoEntity.getId());
			}
			startActivity(intent);
			break;
		case R.id.info_head:
			ZoomImgeDialogFragment.show(mCustomerInfoEntity.getBigHeadIcon(),
					getSupportFragmentManager());
			break;
			//医生推荐
		case R.id.info_recommend:
		case R.id.info_recommend_40:
			if (!mCustomerInfoEntity.getId().equals(SmartFoxClient.getLoginUserId())) {
				sendSMS();
			}
			break;
		case R.id.doctor_message:// 公告板
			intent = new Intent(this, DoctorMessageBoardClient.class);
			intent.putExtra("id", mCustomerInfoEntity.getId());
			intent.putExtra("title", "医生公告");
			startActivity(intent);
			break;
		}

	}

	/**
	 * 短信邀请好友
	 */
	public void sendSMS() {
		Uri smsToUri = Uri.parse("smsto:");
		Intent mIntent = new Intent(android.content.Intent.ACTION_SENDTO,
				smsToUri);
		if (mCustomerInfoEntity != null && !TextUtils.isEmpty(mCustomerInfoEntity.getUsername())) {
			mIntent.putExtra("sms_body", "介绍个医生给你（多美号："+mCustomerInfoEntity.getUsername()+"），TA是这方面专家" +"没有壹健康要先下载：http://yijiankangv.mobi/SJ/download.html");
		}
		startActivity(mIntent);
	}

	@Override
	public void onBackPressed() {
		// 从好友列表除"我的" 进入资料 返回需要刷新列表
		if (getIntent().hasExtra("positon")) {
			Intent i = getIntent();
			i.putExtra("mFriendInformUI", mCustomerInfoEntity);
			i.putExtra("position", getIntent().getExtras().getInt("positon"));
			this.setResult(0, i);
		}
		super.onBackPressed();
	}


	@Override
	public void onRefresh(PullToRefreshBase<ScrollView> refreshView) {
		if (intent.hasExtra("id")) {
			initData(null, null, intent.getStringExtra("id"));
		} else if (intent.hasExtra("info")) {
			if (intent.getExtras().get("info") instanceof CustomerInfoEntity) {
				onBounData((CustomerInfoEntity) intent.getExtras().get("info"));
			}
		}
	}

	// VIP服务
	@Override
	public void onClickCommonService() {
		if (mCustomerInfoEntity != null) {
			if (SmartFoxClient.getLoginUserId().equals(mCustomerInfoEntity.getId())) {SingleBtnFragmentDialog.showDefault(getSupportFragmentManager(),"你自己不能与自己互动");
				return;
			} else {
				HttpRestClient.doHttpEngageTheDialogue(SmartFoxClient.getLoginUserId(),mCustomerInfoEntity.getId(), "1", new AsyncHander(1));
			}
		}
	}
	
	//门诊预约
	@Override
	public void onClickInterviewService() {
		if (mCustomerInfoEntity != null) {
			if (SmartFoxClient.getLoginUserId().equals(mCustomerInfoEntity.getId())) {SingleBtnFragmentDialog.showDefault(getSupportFragmentManager(),
						"你自己不能与自己互动");
				return;
			} else {
				HttpRestClient.doHttpEngageTheDialogue(SmartFoxClient.getLoginUserId(),mCustomerInfoEntity.getId(), "3", new AsyncHander(3));
			}
		}
	}
	
	//网上咨询
	@Override
	public void onClickTimeService() {
		if (mCustomerInfoEntity != null) {
			if (SmartFoxClient.getLoginUserId().equals(mCustomerInfoEntity.getId())) {
				SingleBtnFragmentDialog.showDefault(getSupportFragmentManager(),"你自己不能与自己互动");
			} else {
				HttpRestClient.doHttpEngageTheDialogue(SmartFoxClient.getLoginUserId(),mCustomerInfoEntity.getId(), "2", new AsyncHander(2));
			}
		}
	}

	@Override
	public void onClickProfessionalSalon() {
		intent = new Intent();
		intent.setClass(this, SalonAboutOthersActivity.class);
		// String type = request.getParameter("TYPE"); //0 - 医生沙龙
		// 1- 普通沙龙
		intent.putExtra("type", "0");
		intent.putExtra("mInfoEntity", mCustomerInfoEntity);
		intent.putExtra("title", "医生话题");
		startActivity(intent);
	}

	@Override
	public void onClickCloseService() {
		SingleBtnFragmentDialog.showDefault(getSupportFragmentManager(),
				getString(R.string.closeing_function));
	}

	class AsyncHander extends JsonsfHttpResponseHandler {

		private int type;

		// {"SERVICE_ITEM_DESC":"","witchPage":"1","roleId":"888",
		// // "TickMesg":[{"SERVICE_TYPE_SUB":"按天服务（24小时）","SERVICE_PRICE":1,
		// // "SERVICE_ITEM_ID":2887,"SERVICE_TYPE_SUB_ID":1}]}

		public AsyncHander(int type) {
			super(DoctorMainActivity.this);
			this.type = type;
		}


		@Override
		public void onSuccess(int statusCode,com.alibaba.fastjson.JSONObject response) {
			if (JsonParseUtils.filterErrorMessage(response) == null) {
				Intent intent = new Intent();;
				switch (type) {
				case 1://VIP服务
					intent.setClass(getApplicationContext(), DoctorCommonServiceActivity.class);
					intent.putExtra("response", response.toString());
					intent.putExtra("mCustomerInfoEntity",mCustomerInfoEntity);
					break;
				case 2://网上咨询
					intent.setClass(getApplicationContext(), DoctorTimeServiceActivity.class);
					intent.putExtra("response", response.toString());
					intent.putExtra("mCustomerInfoEntity",mCustomerInfoEntity);
					break;
				case 3://门诊预约服务
					intent.setClass(getApplicationContext(), DoctorInterviewServiceActivity.class);
					intent.putExtra("response", response.toString());
					intent.putExtra("mCustomerInfoEntity",mCustomerInfoEntity);
					break;
				}
				startActivity(intent);
			}else {
				SingleBtnFragmentDialog.showDefault(getSupportFragmentManager(),  JsonParseUtils.filterErrorMessage(response));
			}

			super.onSuccess(statusCode, response);
		}

	}
	/**
	 * 医生公告板
	 */
	@Override
	public void onClickMessage() {
		Intent intent = new Intent(this, DoctorMessageBoardClient.class);
		intent.putExtra("id", mCustomerInfoEntity.getId());
		intent.putExtra("title","医生公告");
		startActivity(intent); 
	}
/**
 * 医生馆服务内容 
 */
	@Override
	public void onClickServiceContent() {
		Intent intent = new Intent(getApplicationContext(),DoctorServiceActivity.class);
		intent.putExtra("userId", mCustomerInfoEntity.getId());
		intent.putExtra("NN", "11");
		startActivity(intent);
	}
	//患者指南
	@Override
	public void onClickPatientGuide() {
		Intent intent = new Intent(this,DocotrStationHelperActivity.class);
		intent.putExtra("type","1");
		startActivity(intent);
	}

}
